import Axios from 'axios';
import Qs from 'qs';


function handleResp(res) {
  let response = res;
  if (typeof response === 'string') {
    response = JSON.parse(response);
  }
  if (response.status === 0) {
    return response.object;
  }
  console.error('接口调用失败!!!');
  return false;
}

// 获取实例添加拦截器
const service = Axios.self();

// 添加请求拦截器
service.interceptors.request.use(
  config => config,
  error => Promise.reject(error)
);

// 添加响应拦截器
service.interceptors.response.use(
  (response) =>
    // 券领取拦截除外
    handleResp(response.data)
  ,
  error => Promise.reject(error)
);

// export default Axios

export default {
  get: (url, data, config) => axios.get(url, data, config),
  post: (url, data, config) => axios.post(url, data, config)
};
